﻿using Fadada.OpenAPI;
using Fadada.OpenAPI.RemoteModels.Accounts;
using Fadada.OpenAPI.RemoteModels.Documents;
using Fadada.OpenAPI.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fadada.OentAPI.Simples
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var ServerUrl = "https://sandboxapi.fadada.com/api/v3";
            var AppId = "FA35667525";
            var AppKey = "GWXJXBGYW48NDBJFNQRVQ5ENNJJTWCKM";
            var client = new FadadaClient(ServerUrl, AppId, AppKey);

            #region 个人实名认证
            var rsp = client.Execute(new GetPersonUnionIdUrlRequest()
            {
                clientId = "181",
                redirectUrl="http://www.baidu.com"
            });
            Response.Write(JsonConvert.SerializeObject(rsp));
            Response.Write("<br/>");
            #endregion

            #region 企业实名认证

            var rsp1 = client.Execute(new GetCompanyUnionIdUrlRequest()
            {
                clientId = "181",
                company = new GetCompanyUnionIdUrlRequest.Company()
                {
                    companyName = "测试公司"
                },
                redirectUrl = "http://www.baidu.com",
                applicant = new GetCompanyUnionIdUrlRequest.Applicant()
                {
                    applicantType = "1",
                    unionId = "test"
                }
            });
            Response.Write(JsonConvert.SerializeObject(rsp1));
            Response.Write("<br/>");
            #endregion

            #region 上传合同
            var file = new System.Net.FileItem(@"c:\1.pdf");
            var rsp2 = client.Execute(new UploadFileRequest()
            {
                fileType = 1,
                fileContent = file,
                fileContentHash = CryptTool.HashDataString(file.Stream, "sha256").ToLower()
            });

            Response.Write(JsonConvert.SerializeObject(rsp2));
            Response.Write("<br/>");
            #endregion


        }
    }
}